cc.Class({
    extends: cc.Component,

    properties: {
        title: {
            default: null,
            type: cc.Label
        },
        t1: {
            default: null,
            type: cc.Node
        },
        t2: {
            default: null,
            type: cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.title.string = "祝贺你！完成了关卡"+Data.current+"。";
    },

    // update (dt) {},

    show() {
        this.saveRecord();
        let allok = true;
        for (let i = 0; i < Data.record.length; i++) {
            if (Data.record[i]===0) {
                allok = false;
                break;
            }
        }
        if (allok) {
            this.t1.active = false;
            this.t2.active = true;
        } else {
            this.t1.active = true;
            this.t2.active = false;
        }
        this.node.active = true;
    },
    onBtnClick() {
        if (Data.current<10) {
            cc.director.loadScene("scene"+(Data.current+1));
        } else {
            cc.director.loadScene("scene1");
        }
    },
    saveRecord() {
        if (Data.record[Data.current-1]===0) {
            Data.record[Data.current-1] = 1;
            if (Data.account) {
                let url = "https://lemanew.91xbc.com:8101/save_record";
                let xhr = new XMLHttpRequest();
                xhr.responseType = "json";
                xhr.timeout = 3000;
                xhr.ontimeout = ()=> {
                    xhr.abort();
                };
                xhr.open('POST', url, true);
                xhr.send(JSON.stringify({a:Data.account,s:Data.school,c:"codeorg",l:0,record:JSON.stringify(Data.record)}));
            }
        }
    }
});
